import { defineConfig, loadEnv } from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import pkg from "./package.json";
import dayjs from "dayjs";
import { wrapperEnv } from "./scripts/buildscripts/getEnv";
import { createVitePlugins } from "./scripts/buildscripts/plugins";

const { dependencies, devDependencies, name, version } = pkg;
const __APP_INFO__ = {
    pkg: { dependencies, devDependencies, name, version },
    lastBuildTime: dayjs().format("YYYY-MM-DD HH:mm:ss")
};

// https://vitejs.dev/config/
export default defineConfig(async ({ mode }) => {
    const env = loadEnv(mode, process.cwd());
    const ViteEnv = wrapperEnv(env);


    return {
        // envDir: resolve(__dirname, "env"),
        define: {
            __APP_INFO__: JSON.stringify(__APP_INFO__),
            __ENV__: [createVitePlugins(ViteEnv), env],
            __VITENV__: ViteEnv
        },
        plugins: [uni(),]
    };
});
